const {ccclass, property} = cc._decorator;

@ccclass
export default class failPanel extends cc.Component {

    @property(cc.Label)
    curScore:cc.Label = null;
    @property(cc.Label)
    bestScore:cc.Label = null;
    @property(cc.Node)
    restartBtn:cc.Node = null;
    @property(cc.Node)
    strutBtn:cc.Node = null;
    @property(cc.Node)
    Level:cc.Node = null;

    // 初始化失败界面
   init(){
       this.node.active = true
       let curScoreText = cc.sys.localStorage.getItem('curScore')
       this.curScore.string = curScoreText
       this.bestScore.string = cc.sys.localStorage.getItem('bestScore')
       this.restartBtn.on('touchstart',this.restartTouch,this)
       this.strutBtn.on('touchstart',this.strutTouch,this)
        if(+curScoreText>5 && +curScoreText<10){
            cc.resources.load('6408',cc.SpriteFrame,(err,res)=>{
            this.Level.getComponent(cc.Sprite).spriteFrame = res
        })
        }
        else if(+curScoreText>=10){
             cc.resources.load('64014',cc.SpriteFrame,(err,res)=>{
            this.Level.getComponent(cc.Sprite).spriteFrame = res
        })
        }


   }

   private restartTouch(){
        cc.tween(this.restartBtn).to(0.1,{scale:0.9}).to(0.1,{scale:1}).call(()=>{
            this.node.active = false
            cc.director.loadScene('game')
        }).start()
   }

   private strutTouch(){
      cc.tween(this.strutBtn).to(0.1,{scale:0.9}).to(0.1,{scale:1}).call(()=>{
            
        }).start()
   }
}
